all files / icon/ icon.vue

23.08% Statements 3/13
0% Branches 0/6
0% Functions 0/3
22.22% Lines 2/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  1×                                                                                            
 
import {getColor} from '../utils'
export default {
  name: 'mu-icon',
  props: {
    value: {
      type: String
    },
    size: {
      type: Number,
      default: 24
    },
    color: {
      type: String,
      default: ''
    }
  },
  computed: {
    iconStyle () {
      return {
        'font-size': this.size + 'px',
        'width': this.size + 'px',
        'height': this.size + 'px',
        'color': getColor(this.color)
      }
    }
  },
  methods: {
    handleClick (e) {
      this.$emit('click', e)
    }
  },
  render (h) {
    const {value, iconStyle, handleClick} = this
    if (!value) return null
    const isMaterial = value.indexOf(':') !== 0
    const text = isMaterial ? value : ''
    return h('i', {
      class: ['mu-icon', isMaterial ? 'material-icons' : value.substring(1)],
      style: iconStyle,
      on: {
        click: handleClick
      }
    }, text)
  }
}